<template>
  <div v-loading="ctx.loading">
    <MkBillPanel ref='billPanelRef' printCode='printKuaiSuFaXue' :bill="ctx.faXue" :showBaseInfo="false">
      <template #button>
        <MkButtonQueryHistory @click="listRef.open()" />
        <MkButtonAdd @click="newEntity" :isEdit="ctx.isEdit" />
        <MkButtonSubmit @click="submit" :loading="ctx.loading" :isEdit="ctx.isEdit" />
        <MkButtonMore>
          <a-menu-item @click="billPanelRef.showCaoZuo()">操作记录</a-menu-item>
        </MkButtonMore>
        <MkButtonMore title="打印" icon="ele-Printer">
          <el-button @click="print" type="text" :disabled="!ctx.faXue.id">打印</el-button>
        </MkButtonMore>
      </template>
      <!-- <MkDragSplitPanel :rightWidth="'0px'">
        <template #left> -->
      <div id="printObj">
        <MkPanelEdit title="患者信息" :showButton="checkIsInThreeDay() && ctx.faXue.danJuZhuangTai != '已作废'" isCollapsed
          v-model:isEdit="ctx.editControl.huanZheIsEdit" v-model:showMore="ctx.isMorePatientInfo" @save="updateHuanZhe">
          <MkForm :model='ctx.traShenQingHuanZheInput' ref='huanZheFormRef' formId='kuaiSuFaXueHuanZhe' :col="4">
            <MkInput label="住院号/患者Id" v-model="ctx.traShenQingHuanZheInput.huanZheId" prop="huanZheId"
              :isEdit="ctx.editControl.huanZheIsEdit" />
            <MkInput label="姓名" v-model.trim="ctx.traShenQingHuanZheInput.xingMing" prop="xingMing"
              :isEdit="ctx.editControl.huanZheIsEdit" />
            <MkInputTwo label="性别" label2="年龄" prop="xingBie" prop2="nianLing">
              <template #input1>
                <MkSelectNoLabel v-model="ctx.traShenQingHuanZheInput.xingBie" :isEdit="ctx.editControl.huanZheIsEdit"
                  style="width: 100%" :options="['男', '女']" selectId="KuaiSuFaXue_XingBie" />
              </template>
              <template #input2>
                <el-input v-model="ctx.traShenQingHuanZheInput.nianLing" :disabled="!ctx.editControl.huanZheIsEdit"
                  style="width: 100%" />
              </template>
            </MkInputTwo>
            <MkSelectXueXing prop="chuShaiABO" v-model:model1="ctx.traShenQingHuanZheInput.chuShaiABO"
              v-model:model2="ctx.traShenQingHuanZheInput.chuShaiRhD" :isEdit="ctx.editControl.huanZheIsEdit" />
            <MkSelect label="就诊类型" :options="['住院', '门诊']" v-model.trim="ctx.traShenQingHuanZheInput.jiuZhenLeiXing"
              prop="jiuZhenLeiXing" :isEdit="ctx.editControl.huanZheIsEdit" selectId="kuaisu_jiuZhenLeiXing" />
            <MkInput label="病区" v-model.trim="ctx.traShenQingHuanZheInput.bingQu" prop="bingQu"
              :isEdit="ctx.editControl.huanZheIsEdit" />
            <MkInput label="床号" v-model.trim="ctx.traShenQingHuanZheInput.chuangHao" prop="chuangHao"
              :isEdit="ctx.editControl.huanZheIsEdit" />
            <el-row>
              <MkInput v-model="ctx.traShenQingHuanZheInput.linChuangZhenDuan" label="诊断" prop="linChuangZhenDuan"
                :col="2" :isEdit="ctx.editControl.huanZheIsEdit" />
              <MkInput v-model="ctx.traShenQingHuanZheInput.iCDBianMa" label="ICD诊断码" prop="iCDBianMa"
                :isEdit="ctx.editControl.huanZheIsEdit" />
            </el-row>
            <el-row v-show="ctx.isMorePatientInfo">
              <MkSelect v-model="ctx.traShenQingHuanZheInput.shuXueShi" label="输血史" prop="shuXueShi"
                :isEdit="ctx.editControl.huanZheIsEdit" :options="['有', '无']" />
              <MkSelect v-model="ctx.traShenQingHuanZheInput.shuXueFanYingShi" label="输血反应史" prop="shuXueFanYingShi"
                :isEdit="ctx.editControl.huanZheIsEdit" :options="['有', '无']" />
              <MkSelectEdit label="孕产史" prop="yunChanShi" :isEdit="ctx.editControl.huanZheIsEdit"
                v-model="ctx.traShenQingHuanZheInput.yunChanShi"
                :options="[{ title: '无', canEdit: false, }, { title: '有 , 孕 x, 产 x', canEdit: true, }]">
              </MkSelectEdit>
              <MkSelectEdit label="移植史" prop="yiZhiShi" :isEdit="ctx.editControl.huanZheIsEdit"
                v-model="ctx.traShenQingHuanZheInput.yiZhiShi" :col="2"
                :options="[{ title: '无', canEdit: false, }, { title: '有 , xx年x月x日 , 供着血型 ABO / Rh(D)', canEdit: true, }]">
              </MkSelectEdit>
              <MkInputTwo label="身高" label2="体重" prop="shenGao" prop2="tiZhong">
                <template #input1>
                  <el-input-number prop="shenGao" v-model="ctx.traShenQingHuanZheInput.shenGao"
                    :disabled="!ctx.editControl.huanZheIsEdit" style="width: 100%" :min="30" :max="300"
                    :controls="false">
                    <template #suffix> cm </template>
                  </el-input-number>
                </template>
                <template #input2>
                  <el-input-number prop="tiZhong" v-model="ctx.traShenQingHuanZheInput.tiZhong"
                    :disabled="!ctx.editControl.huanZheIsEdit" style="width: 100%" :min="2" :max="300"
                    :controls="false">
                    <template #suffix> kg </template>
                  </el-input-number>
                </template>
              </MkInputTwo>
            </el-row>
          </MkForm>
        </MkPanelEdit>
        <div style="overflow:hidden;">
          <el-tabs v-model="activeName" type="card">
            <el-tab-pane lazy label="用血申请" name="用血申请" style="overflow:hidden;">
              <MkPanelEdit title="用血申请信息" :showButton="checkIsInThreeDay() && ctx.faXue.danJuZhuangTai != '已作废'"
                v-model:isEdit="ctx.editControl.shenQingYongXueIsEdit" @save="updateYongXue">
                <MkForm :model='ctx.traShenQingYongXueInput' ref='shenQingYongXueFormRef'
                  formId='kuaiSuFaXueShenQingYongXue' :col="4">
                  <MkSelectEnum enumType="ShenQingLeiXing" label="用血类型"
                    v-model="ctx.traShenQingYongXueInput.yongXueLeiXing" prop="yongXueLeiXing"
                    :isEdit="ctx.editControl.shenQingYongXueIsEdit" />
                  <MkInput label="输血目的" v-model="ctx.traShenQingYongXueInput.shuXueMuDi" prop="shuXueMuDi"
                    :isEdit="ctx.editControl.shenQingYongXueIsEdit" :col="2" />
                  <el-row>
                    <MkSelectBasEntity label="申请品种" v-model="ctx.traShenQingYongXueInput.shenQingPinZhong"
                      prop="shenQingPinZhong" :isEdit="ctx.editControl.shenQingYongXueIsEdit" entity="BasXueYePinZhong"
                      @change="handlePinZhongChange" />
                    <MkInputNumber label="申请量" v-model="ctx.traShenQingYongXueInput.shenQingLiang" prop='shenQingLiang'
                      :isEdit="ctx.editControl.shenQingYongXueIsEdit">
                      <template #suffix>
                        <span>{{ ctx.shenQingPinZhongDanWei }}</span>
                      </template>
                    </MkInputNumber>
                    <MkInput label="申请单号" v-model="ctx.traShenQingInput.id" prop="id" :isEdit="false" />
                  </el-row>
                  <el-row>
                    <MkInput label="申请医生" v-model="ctx.traShenQingInput.createUserName" prop="createUserName"
                      :isEdit="false" />
                    <MkInput label="上级医生" v-model="ctx.traShenQingInput.shangJiShenHeRen" prop="shangJiShenHeRen"
                      :isEdit="ctx.editControl.shenQingYongXueIsEdit" />
                    <MkInput label="科主任" v-model="ctx.traShenQingInput.keZhuRenShenHeRen" prop="keZhuRenShenHeRen"
                      :isEdit="ctx.editControl.shenQingYongXueIsEdit" />
                  </el-row>
                </MkForm>
              </MkPanelEdit>
            </el-tab-pane>
            <el-tab-pane lazy label="血型复核" name="血型复核" style="overflow:hidden;">
              <MkPanelEdit title="血型复核" :showButton="checkIsInThreeDay() && ctx.faXue.danJuZhuangTai != '已作废'"
                v-model:isEdit="ctx.editControl.fuHeIsEdit" @save="updateFuHe">
                <MkForm :model="ctx.traFuHeInput" formId="kuaiSuFaXueFuHe" ref="fuHeFormRef" :col="4">
                  <el-row>
                    <!-- <MkInput v-model="ctx.traFuHeInput.aboJianDing" label="ABO鉴定方法" :isEdit="ctx.editControl.fuHeIsEdit" />
                <MkInput v-model="ctx.traFuHeInput.rhdJianDing" label="Rh(D)鉴定方法" :isEdit="ctx.editControl.fuHeIsEdit" /> -->
                    <MkSelectEnum enumType="ABOFuHeJieGuo" v-model="ctx.traFuHeInput.aboFuHeJieGuo" prop="aboFuHeJieGuo"
                      label="ABO复核结果" :isEdit="ctx.editControl.fuHeIsEdit" />
                    <MkSelectEnum enumType="RhDFuHeJieGuo" v-model="ctx.traFuHeInput.rhDFuHeJieGuo" prop="rhDFuHeJieGuo"
                      label="Rh(D)复核结果" :isEdit="ctx.editControl.fuHeIsEdit" />
                    <MkSelectEnum enumType="KangShaiJieGuo" v-model="ctx.traFuHeInput.kangShaiJieGuo"
                      prop="kangShaiJieGuo" label="抗体筛选结果" :isEdit="ctx.editControl.fuHeIsEdit" />
                  </el-row>
                  <MkSelectUser label="检验人" v-model="ctx.traFuHeInput.jianYanRenId" prop="jianYanRenId"
                    :isEdit="ctx.editControl.fuHeIsEdit" />
                  <MkSelectUser label="复检人" v-model="ctx.traFuHeInput.fuHeRenId" prop="fuHeRenId"
                    :isEdit="ctx.editControl.fuHeIsEdit" />
                  <MkFormDateTime label="检验时间" v-model="ctx.traFuHeInput.jianYanShiJian" prop="jianYanShiJian"
                    :editable="ctx.editControl.fuHeIsEdit" />
                </MkForm>
              </MkPanelEdit>
            </el-tab-pane>
            <el-tab-pane lazy label="发血信息" name="发血信息" style="overflow:hidden;">
              <MkPanelEdit title="发血信息" :showButton="checkIsInThreeDay() && ctx.faXue.danJuZhuangTai != '已作废'"
                v-model:isEdit="ctx.editControl.faXueIsEdit" @save="updateFaXue">
                <MkForm :model="ctx.faXue" ref="kuaiSuFaXueFromRef" formId="kuaiSuFaXueFaXue" :col="4">
                  <MkInput label="取血人" v-model="ctx.faXue.quXueRen" prop="quXueRen"
                    :isEdit="ctx.editControl.faXueIsEdit" />
                  <MkInput label="输血前体温" v-model="ctx.faXue.shuXueQianTiWen" prop="shuXueQianTiWen"
                    :isEdit="ctx.editControl.faXueIsEdit" />
                  <MkInput label="备注" v-model="ctx.faXue.remark" prop="remark" :isEdit="ctx.editControl.faXueIsEdit"
                    :col="2" />
                </MkForm>
              </MkPanelEdit>
              <MkPanelEdit title="发血明细" :showButton="checkIsInThreeDay() && ctx.faXue.danJuZhuangTai != '已作废'"
                v-model:isEdit="ctx.editControl.faXueMingXiIsEdit" @save="updateFaXueMingXi">
                <MkXueYeScanInput ref="scanRef" @onEnter="scanEnter" width="400px" scanInpWidth="400px"
                  v-if="ctx.editControl.faXueMingXiIsEdit && ctx.faXue.danJuZhuangTai != '已生效'" />
                <br>
                <MkTable :data="ctx.traKuaiSuFaXueMingXiList" default-expand-all>
                  <el-table-column type="expand" fixed>
                    <template #default="{ row }">
                      <MkTextXueYe :xueYe="row.invKuCun" style="margin-left: 50px;" />
                    </template>
                  </el-table-column>
                  <MkColumnIndex />
                  <MkColumnInputEnum enumType="ZhuCiCe" prop="zhuCe" label="主侧"
                    :isEdit="ctx.editControl.faXueMingXiIsEdit" />
                  <MkColumnInputEnum enumType="ZhuCiCe" prop="ciCe" label="次侧"
                    :isEdit="ctx.editControl.faXueMingXiIsEdit" />
                  <MkColumnInputEnum enumType="PeiXueJieGuo" prop="peiXueJieGuo" label="配血结果"
                    :isEdit="ctx.editControl.faXueMingXiIsEdit" />
                  <MkColumnInputUser prop="peiXueRenId" label="配血者" :isEdit="ctx.editControl.faXueMingXiIsEdit" />
                  <MkColumnInputUser prop="fuHeRenId" label="复核者" :isEdit="ctx.editControl.faXueMingXiIsEdit" />
                  <MkColumnInputDate prop="peiXueRiQi" width="200px" label="配血时间"
                    :isEdit="ctx.editControl.faXueMingXiIsEdit" />
                  <MkColumnInputSelect :options="['微柱凝集法']" selectId="peiXue_peiXueFangFa" prop="peiXueFangFa"
                    label="配血方法" :isEdit="ctx.editControl.faXueMingXiIsEdit" />
                  <MkColumnInputSelect :options="['微柱凝集法']" selectId="peiXue_fuHePeiXueFangFa" prop="fuHePeiXueFangFa"
                    label="复核配血方法" :isEdit="ctx.editControl.faXueMingXiIsEdit" />
                  <el-table-column label="操作" width="120px" fixed="right"
                    v-if="ctx.editControl.faXueMingXiIsEdit && ctx.faXue.danJuZhuangTai != '已生效'">
                    <template #default="{ row }">
                      <el-button icon="ele-Delete" size="small" text type="danger" @click="delBlood(row)">删除</el-button>
                    </template>
                  </el-table-column>
                </MkTable>
              </MkPanelEdit>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
    </MkBillPanel>
    <List ref="listRef" @load="loadEntity" />
  </div>
</template>

<script lang='ts' setup>
import List from './list.vue'
import { isNull } from '/@/utils'
import {
  billPanelRef,
  huanZheFormRef,
  shenQingYongXueFormRef,
  fuHeFormRef,
  kuaiSuFaXueFromRef,
  listRef,
  scanRef,
  ctx,
  newEntity,
  checkIsInThreeDay,
  submit,
  audit,
  print,
  scanEnter,
  delBlood,
  loadEntity,
  getJianYanList,
  handlePinZhongChange,
  updateHuanZhe,
  updateYongXue,
  updateFuHe,
  updateFaXue,
  updateFaXueMingXi
} from './index'

const activeName = ref('用血申请')

</script>

<style lang='scss' scoped></style>